<?php

namespace app\api\controller\applets;

use app\common\controller\Api;
use EasyWeChat\Factory;
use fast\Random;
use think\App;
use think\Db;
use think\facade\Validate;
use think\facade\Config;
use app\common\library\Ems;
use app\common\library\Sms;
use think\Request;

/**
 * 订单接口.
 */
class Order extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';

    protected $model;
    /**
     * 构造方法
     * @access public
     * @param Request $request Request 对象
     */
    public function __construct(Request $request = null)
    {
        parent::__construct(App::getInstance());
        $this->model = new \app\api\model\Order();
    }

    public function _initialize()
    {
        parent::_initialize();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }

    /**
     * 订单列表.
     */
    public function orderList()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->orderList($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 订单详情.
     */
    public function orderDetails()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->orderDetails($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 提交订单页.
     */
    public function orderPage()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->orderPage($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 下单支付.
     */
    public function orderPay()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->orderPay($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 取消支付接口.
     */
    public function cancelPay()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->cancelPay($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 取消预约.
     */
    public function orderRefund()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->orderRefund($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 支付成功页面.
     */
    public function orderSuccess()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->orderSuccess($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 续租.
     */
    public function continue()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->continue($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 续租订单详情.
     */
    public function continueDetail()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->continueDetail($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 当面收费订单详情.
     */
    public function faceDetail()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->faceDetail($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 续租支付.
     */
    public function continuePay()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->continuePay($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 换车支付.
     */
    public function changePay()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->changePay($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 当面付支付.
     */
    public function facePay()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->facePay($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 换车总退款申请.
     */
    public function changeRefund()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUser();
        $data  = $this->model->changeRefund($requestData, $user);
        $this->getReturnData($data);
    }

}
